package com.yonyougov.devops.cruxcisupport.k8s.rest.service;

import com.yonyougov.devops.cruxcisupport.k8s.error.K8sConfIgNotFindException;
import com.yonyougov.devops.cruxcisupport.k8s.pod.PodStatusInfo;
import com.yonyougov.devops.cruxcisupport.k8s.rest.*;
import com.yonyougov.devops.cruxcisupport.k8s.rest.vo.PodEventVo;
import lombok.SneakyThrows;

import java.math.BigInteger;
import java.util.List;

public interface K8sDeploymentService {
    @SneakyThrows
    void createConfigMap(BigInteger envId, String envName) throws Exception;

    /**
     * 创建pod
     * @param request 入参
     */
    void createDeployment(DeploymentRestRequest request) throws Exception;

    /**
     * 批量创建pod
     * @param request 入参
     */
    void batchCreateDeployment(BatchDeploymentRestRequest request) throws Exception ;

    /**
     * 从多少秒之前获取pod日志
     * @param request 参数
     * @return String
     * @throws Exception 异常
     */
    String getPodLog(PodLogRestRequest request) throws Exception;

    /**
     * 获取pod名称
     * @param request 参数
     * @return List<String>
     * @throws K8sConfIgNotFindException 异常
     */
    List<String> getPodNames(PodNameRestRequest request) throws K8sConfIgNotFindException;

    /**
     * 获取某个命名空间下所有的pod详情
     * @param request 请求参数{envName:xxx}
     * @return List<PodStatusInfo> com.yonyougov.devops.cruxcisupport.k8s.pod.PodStatusInfo
     */
    List<PodStatusInfo> getPodDetailsByNameSpace(PodDetailsRestRequest request) throws K8sConfIgNotFindException;

    /**
     * 删除某个命名空间下指定的Deployment 以及service
     * @param request com.yonyougov.devops.cruxcisupport.k8s.rest.PodBatchDelRestRequest
     * @return boolean
     */
    boolean deleteBatchPod(PodBatchDelRestRequest request) throws K8sConfIgNotFindException;

    /**
     * 获取pod的Event信息
     *
     * @param request 请求参数
     * @return com.yonyougov.devops.cruxcisupport.k8s.rest.vo.PodEventVo
     */
    List<PodEventVo> getEventsByPodName(PodEventRestRequest request) throws K8sConfIgNotFindException;

    /**
     * 查询已经部署的第一个服务名称
     *
     * @param env  环境名称
     * @param apps 应用名称
     * @return 应用名称
     * @throws K8sConfIgNotFindException
     */
    String findFristDeploy(String env, String... apps) throws K8sConfIgNotFindException;
}
